//
//  SiterRoomNetManager.m
//  AFNetworking
//
//  Created by Henry on 2023/3/13.
//

#import "SiterRoomNetManager.h"
#import "SiterAPI.h"

@implementation SiterRoomNetManager


//获取房间列表
+ (void) getRoomList:(void(^)(id,NSError *,NSError *)) handler{

    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/addrRoom/getAddrRoomList",[[Siter sharedInstance] getDomain]] parameters:nil completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//增加默认房间
+ (void) addDefaultRoom:(void(^)(id,NSError *,NSError *)) handler{

    NSArray *appLanguages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
     NSString *languageName = [appLanguages objectAtIndex:0];
    NSArray *array = nil;
    if([languageName containsString:@"zh"]){
        array = @[@"客厅",@"餐厅",@"厨房"];
    }else{
        array = @[@"Living room",@"Dining room",@"Kitchen"];
    }

    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/addrRoom/addDefaultRoom",[[Siter sharedInstance] getDomain]] parameters:array completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//获取房间列表
+ (void) addRoom:(NSString *)roomName withhandler:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *dic = @{@"room":roomName};
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/addrRoom/add",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//删除房间
+ (void) deleteRoom:(NSNumber *)roomId withhandler:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *dic = @{@"id":roomId};
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/addrRoom/delete",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//修改房间名
+ (void) modifyRoomName:(NSString *)roomName withRoomId:(NSNumber *)roomId withhandler:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *dic = @{@"room":roomName,@"id":roomId};
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/addrRoom/modify",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//修改设备房间
+ (void) modifyRoomWithThing:(NSString *)thingName withRoomId:(NSNumber *)roomId withhandler:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *dic = @{@"thingName":thingName,@"roomId":roomId};
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/bind/modifyRoomId",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//修改子设备房间
+ (void) modifyRoomWithSubDev:(NSString *)thingName withDeviceCode:(NSString *)deviceCode withDeviceCode:(NSNumber *)roomId handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *dic = @{
                          @"roomId" : roomId,
                          @"deviceCode" : deviceCode,
                          @"gateway" : thingName
                          };
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/sub/modifyBySnAndGatething",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


@end
